#Include <WinAPI.au3>
WinActivate("World of Warcraft")
WinWaitActive("World of Warcraft")

;Global $WinSize = GetWinSize("World of Warcraft")
;Global $LootY = $WinSize[0] / 2
;$LootY = $LootY / 2
;Global $LootX = $WinSize[1] / 2
		
Global $Lite = ObjCreate("SERFLITEMAX20.Core.Main")
$Lite.Start

While 1
	
	
	Send("/cast Horn Of Winter")
	if $Lite.AttackTarget Then
 
		if $Lite.TargetHasLife then
			;cast buffs
			Send("/cast Horn Of Winter")
			Send("/cast Bone Shield")
		endif
		
		
		while $Lite.TargetHasLife
			while Not $Lite.TargetInLOS 
				Send("{a down}") ;Holds the a key down
				Sleep(100)
				Send("{a up}") ;Releases the a key
			wend
			
			GlobalCast("Icy Touch")
			;GlobalCast("Plague Strike")
			;GlobalCast("Blood Strike")

		WEnd
		Sleep(3000)
		
		
		;loot
		MouseClick("right",$LootX, $LootY, 1, 0)
		Sleep(4000)
		;reset position
		Send("^{NUMPADMULT}")
		Sleep(3000)
	endif
	 
	Sleep(500)
WEnd

Exit

func GlobalCast($Spell)
	Send("/cast " & $Spell)
	Sleep(2100)
endfunc

Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf

EndFunc

Func GetWinSize($Title)

	$var = WinList($Title)
	Local $hWnd;
	For $i = 1 to $var[0][0]
		; Only display visble windows that have a title
		If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then
			;MsgBox(0, "Details", "Title=" & $var[$i][0] & @LF & "Handle=" & $var[$i][1])
			$hWnd = $var[$i][1]
		EndIf
	Next
	local $result[2]

	$result[0] = _WinAPI_GetWindowHeight($hWnd)
	$result[1] = _WinAPI_GetWindowWidth($hWnd)

	return $result
EndFunc